fix: Remember-me token refresh fails in loginView() - missing ->withCookies() on redirect #1305#1306
Open
tomatlscomm wants to merge 1 commit intocodeigniter4:developfrom
Open
fix: Remember-me token refresh fails in loginView() - missing ->withCookies() on redirect #1305#1306tomatlscomm wants to merge 1 commit intocodeigniter4:developfrom
tomatlscomm wants to merge 1 commit intocodeigniter4:developfrom
Conversation
…ookies() on redirect codeigniter4#1305
Collaborator
|
Please write unit tests for this change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a user with a valid remember-me cookie accesses the login page, the loginView() method in LoginController redirects already-logged-in users without preserving cookies.
Bug Location:
vendor/codeigniter4/shield/src/Controllers/LoginController.php:34
Current Code:
Expected Code:
Impact:
When Session::checkRememberMe() validates a remember-me token, it calls refreshRememberMeToken() which:
Generates a new validator
Updates the hashed validator in database
Sends a new cookie via setRememberMeCookie()
However, the redirect at line 34 doesn't include ->withCookies(), so the new cookie is lost. The browser keeps the old cookie with the old validator, which no longer matches the updated hash in the database.
On the next visit, authentication fails with:
hash_equals($token->hashedValidator, $hashedValidator) === false // Session.php:631
Steps to Reproduce
Enable remember-me: $sessionConfig['allowRemembering'] = true
Login with remember-me checkbox checked
Wait for token refresh (or clear session to trigger remember-me authentication)
Access login page → redirect happens but new cookie is lost
Next visit → authentication fails because cookie validator doesn't match database hash
Expected Output
Expected Code:
=> The token will be refreshed in the cookie